//
//  DSFriendsRecommendModel.m
//  budejie
//
//  Created by tangQiang on 8/27/16.
//  Copyright © 2016 Dason. All rights reserved.
//

#import "DSFriendsRecommendModel.h"

@interface DSFriendsRecommendModel ()
/**
 *  下载管理类
 */
//@property (strong, nonatomic) AFHTTPSessionManager *manager;
@end

@implementation DSFriendsRecommendModel

#pragma mark - 自定义构造方法
+ (instancetype)friendsRecommendMdoelWithDic:(NSDictionary *)dic {
    DSFriendsRecommendModel *friendsRecommendModel = [[DSFriendsRecommendModel alloc]init];
    [friendsRecommendModel setValuesForKeysWithDictionary:dic];
    return friendsRecommendModel;
}

#pragma mark - 重写 setValue 的方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    if ([key isEqualToString:@"id"]) {
        self.ID = value;
    }
}

#pragma mark - 下载数据
+ (void)downloadDataWithString:(NSString *)urlstr successBlcok:(void (^)(NSArray<DSFriendsRecommendModel *> *))successblock failblock:(void (^)(NSError *))failblock {
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithBaseURL:[NSURL URLWithString:@"http://api.budejie.com"]];
    NSDictionary *dic = @{
                          @"a" : @"category",
                          @"c" : @"subscribe",
                          };
    [manager GET:@"api/api_open.php" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       //NSLog(@"%@",responseObject);
        NSDictionary *dic = responseObject;
        NSArray *arr = dic[@"list"];
        NSMutableArray<DSFriendsRecommendModel *> *arrM = [NSMutableArray arrayWithCapacity:arr.count];
        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            DSFriendsRecommendModel *friendRecommendModel = [self friendsRecommendMdoelWithDic:obj];
            [arrM addObject:friendRecommendModel];
        }];
        if (successblock) {
            successblock(arrM.copy);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failblock) {
            failblock(error);
        }
    }];
}



@end
